#include <QApplication>
#include <QFile>
#include <QLocale>
#include <QSettings>
#include <QTextStream>
#include <QTranslator>

#include <QtCrypto>
#include <QtDebug>

#include "src/cgui.h"
#include "src/cstartdialog.h"
#include "src/constants.h"

#include "src/creplicator.h"

#ifndef IS_MOBILE
void myMessageOutput(QtMsgType, const char *msg)
{
    QString result;
    result += msg;
    result += QChar('\n');
    QFile file("passworder.log");
    file.open(QIODevice::Append);
    QTextStream out(&file);
    out.setCodec("UTF-8");
    out << result;
    file.close();
    fprintf(stdout, "%s", result.toAscii().data());
}
#endif

int main(int argc, char *argv[])
{
#ifndef IS_MOBILE
    //qInstallMsgHandler(myMessageOutput);
#endif
    QApplication a(argc, argv);
    //QApplication::setStyle("Cleanlooks");

    QString filename = ":/ts/" + QLocale::system().name() + ".qm";

    QTranslator tr;
    if(tr.load(filename))
    {
        qDebug() << "[SYSTEM] Translation loaded successfully: " + filename;
        a.installTranslator(&tr);
    }
    else
        qDebug() << "[SYSTEM] Translation loading failed: " + filename;


    QCA::Initializer init;
    QCA::scanForPlugins();

    QSettings *settings = new QSettings("passworder.ini", QSettings::IniFormat);

    CGui *w = new CGui(settings);
    w->start();

    return a.exec();
}
